#!/bin/bash
# 这个脚本用于检查合服，跨服boss的后台列表和邮件是否一致

check_hefu_mail(){
    merge_mail=/data/tx-merge.mail
    houtai_list=/data/tx-merge.houtai

    if [ -f $merge_mail ] && [ -f $houtai_list ];then

        echo "邮件行数:`wc -l $merge_mail`"
        echo "后台行数:`wc -l $houtai_list`"

        echo "邮件缺少的组:"
        for i in `awk -F"|" '{print $2","$3}' ${houtai_list}`;do
            grep "$i" ${merge_mail} &>/dev/null || echo $i
        done

        echo "============================"

        echo "后台缺少的组:"
        awk -F"|" '{print $2","$3}' ${houtai_list} > /tmp/houtai.tmp
        for i in `cat ${merge_mail}`;do
            grep "$i" /tmp/houtai.tmp &>/dev/null || echo $i
        done

    else
        echo "请确保 /data/tx-merge.mail 和 /data/tx-merge.houtai 存在"
        exit 1
    fi
}

check_kuafuboss_mail(){
    houtai_list=/data/tx_kuafuboss.houtai
    boss_mail_list="/data/tx_kuafuboss.mail"

    if [ -f ${houtai_list} ] && [ -f ${boss_mail_list} ];then

        echo "邮件行数:`wc -l $boss_mail_list`"
        echo "后台行数:`wc -l $houtai_list`"

        echo "邮件缺少的组:"
        for i in `cat ${houtai_list}`;do
            grep "$i" ${boss_mail_list} &>/dev/null || echo $i
        done

        echo "============================"

        echo "后台缺少的组:"
        # awk -F"|" '{print $2","$3}' ${houtai_list} > /tmp/houtai.tmp
        for i in `cat ${boss_mail_list}`;do
            grep "$i" ${houtai_list} &>/dev/null || echo $i
        done

    else
        echo "请确保 /data/tx_kuafuboss.mail 和 /data/tx_kuafuboss.houtai 存在"
        exit 1
    fi   
}

case  $1 in
'merge')
    check_hefu_mail
    ;;
'kuafuboss')
    check_kuafuboss_mail
    ;;
*)
    echo "`basename $0`:merge/kuafuboss"
    ;;
esac
